import os
from datetime import datetime
from typing import TypedDict, Union, List, Optional


class ReviewData(TypedDict):
    """ Данные отзыва """

    evaluation: int
    name: str
    card_number: str
    is_below_four: bool
    description: str


class ProductInformationData(TypedDict):
    """ Информаци о продукте (все вместе) """

    date: datetime
    name: str
    raiting: Union[int, float]
    number_of_raitings: int
    link: str


class PointsOfSaleData(TypedDict):
    """ Точки продаж продукта """

    list_of_points_of_sale: Union[List[str], List]


class ProductData(TypedDict):
    """ Данные продукта """

    information: ProductInformationData
    reviews: Union[List, List[ReviewData]]
    points_of_sale: PointsOfSaleData


class ProxyData(TypedDict):
    """ Прокси """

    ip: str
    port: str
    login: str
    password: str


def get_list_of_proxies() -> List[ProxyData]:
    """ Получаем список прокси """

    result = []
    file_path = os.path.abspath('user_data/list_of_proxies.txt')

    with open(file_path) as file:
        list_of_proxies = file.read().strip().split('\n\n')

    for proxy in list_of_proxies:
        ip, port, login, password = proxy.split('\n')
        proxy_data = ProxyData(
            ip=ip,
            port=port,
            login=login,
            password=password
        )
        result.append(proxy_data)

    return result
